﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevTeam;
using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo.Kauf
{
    public partial class KaufDosyaBilgileri : XForm
    {
        DataTable dtOrder;
        string idxs;
        string tip = string.Empty;
        public KaufDosyaBilgileri()
        {
            InitializeComponent();
        }
        public KaufDosyaBilgileri(string idxs, DataTable dtOrder)
            : this()
        {
            this.dtOrder = dtOrder;
            this.idxs = idxs;
        }

        public string Atolye
        {
            get 
            {
                return AppSession.Lookups.V_CariA.FindByCariId(gleAtolye.EditValue.ToInt()).Name.ToString();
            }
        }

        private void KaufDosyaBilgileri_Load(object sender, EventArgs e)
        {
            int TalepTipiId = dtOrder.Rows[0]["TalepTipiId"].ToInt();
            if (TalepTipiId != 1)
            {
                cbTip.Properties.Items.AddRange(new object[] { "Numune" });
                cbTip.EditValue = "Numune";
                tip = "N";
                gleAtolye.EditValue = 293;
            }
            else
            {
                cbTip.Properties.Items.AddRange(new object[] { "Fason", "Karbel" }); 
                cbTip.EditValue = "Fason";
                tip = "F";
            }

            lblAdet.Text = dtOrder.Compute("sum(Total)", "").ToString();
            txtKalip.Text = dtOrder.Rows[0]["Kalip"].ToString();
            txtModelNo.Text = dtOrder.Rows[0]["ModelNo"].ToString();
            txtModel.Text = dtOrder.Rows[0]["Model"].ToString();
            gleAtolye.Properties.Assign(RI(Rp.V_CariA));

            cbTip.SelectedIndexChanged += new EventHandler(cbTip_SelectedIndexChanged);
            btnOk.Click+=new EventHandler(btnOk_Click);
            btnCancel.Click+=new EventHandler(btnCancel_Click);
        }

        void cbTip_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cbTip.SelectedItem.ToStr())
            {
                case "Fason":
                    tip = "F";
                    break;
                case "Karbel":
                    tip = "K";
                    break;
                case "Numune":
                    tip = "N";
                    break;
            }

            if (tip == "K")
                gleAtolye.EditValue = 293;
            else
                gleAtolye.EditValue = null;

            gleAtolye.Enabled = tip != "K";
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        void btnOk_Click(object sender, EventArgs e)
        {
            if (tip=="")
            {
                ShowErrorMessage("Dosya türü seçin !");
                return;
            }
            this.DialogResult = DialogResult.OK;
            Session.DataManager.ExecuteDataSet("UpdKaufKesimNo", 
                                                idxs, 
                                                txtKalip.Text, 
                                                txtModel.Text, 
                                                txtModelNo.Text,  
                                                txtAciklama.Text,
                                                WhoAmI, 
                                                tip,
                                                gleAtolye.EditValue);
        }       
    }
}